package poly_.polyarr;

public class PolyArray {
    public static void main(String[] args) {
        Person[] persons = new Person[5];
        persons[0] = new Person("jack", 10);
        persons[1] = new Student("tom", 20, 90);
        persons[2] = new Student("marry", 13, 100);
        persons[3] = new Teacher("lisi", 30, 8000);
        persons[4] = new Teacher("king", 50, 20000);

        for(int i = 0; i < persons.length; i++) {
            //person[i]编译类型是Person，运行类型是根据实际情况由JVM来判断
            System.out.println(persons[i].say()); // 动态绑定机制

            //类型判断+向下转型
            if(persons[i] instanceof Student) {
//                Student st = (Student)persons[i];
//                st.study();
                ((Student)persons[i]).study();
            } else if (persons[i] instanceof Teacher) {
//                Teacher teach = (Teacher)persons[i];
//                teach.teach();
                ((Teacher)persons[i]).teach();
            } else if(persons[i] instanceof Person){

            } else {
                System.out.println("你的类型有误，请自己检查...");
            }
        }
    }
}
